module windump.plugins.htmlinput.ie.shell;

import std.c.windows.windows;

import windump.utf;
import windump.combase;
import shdocvw = windump.plugins.htmlinput.ie.shdocvw;
import html = windump.plugins.htmlinput.ie.html;



class ShellWindows
{
	private shdocvw.IShellWindows m_sw;

	public this()
	{
		m_sw = 
			shdocvw.ShellWindows.coCreate!(shdocvw.IShellWindows)();
	}

	public ~this()
	{
		tryRelease(m_sw);
	}

	public int count()
	{
		int n;
		HRESULT hr = m_sw.get_Count(n);

		return n;
	}

	public html.WebBrowser getItem(int index)
	{
		IDispatch disp;
		HRESULT hr = m_sw.Item(VARIANT(index), disp);
		if(hr != S_OK)
			throw new html.HtmlException("failed to get WebBrowser");
		html.IWebBrowser browser = com_cast!(html.IWebBrowser)(disp);
		if(browser is null)
			throw new html.HtmlException("failed to cast the browser ptr");
		auto br = new html.WebBrowser(browser);
		return br;
	}


/*	int enumBrowsers( int delegate() proc)
	{
	}
*/
		
}




/+void doReplace()
{
	IShellWindows sw = ShellWindows.coCreate!(IShellWindows)();
	scope(exit) tryRelease(sw);
	int count;
	sw.get_Count(count);
	for(int i = 0; i < count; i++)
	{
		HRESULT hr;
		IWebBrowser browser;
		IDispatch disp, dispDoc;
		hr = sw.Item(VARIANT(i), disp);
		if(hr != S_OK)continue;
		browser = com_cast!(IWebBrowser)(disp);		
		if(browser is null)continue;
		hr = browser.get_Document(disp);
		if(hr != S_OK)continue;
		IHTMLDocument3 doc = com_cast!(IHTMLDocument3)(disp);
		if(doc is null)continue;
		wchar* url;
		browser.get_LocationURL(url);
		writefln(toUtf8(url));
		IHTMLElement ele;
		writefln("ele");
		/*hr = doc.getElementById("safeEdit1", ele);
		writefln("ele2");
		if(hr != S_OK)continue;
		ele.set_outerHTML("<input type=\"password\" width=145 heigh=21 />");
*/
		writefln("ele3");
		scope(exit)
		{
			freeBstr(url);
			tryRelease(ele);
			tryRelease(doc);
			tryRelease(browser);
		}

	}
}+/
